package my;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Database {
	
	protected String database;
	protected String url;
	protected String port;
	protected String user;
	protected String password;
	protected Statement st = null;
	protected Connection con = null;
	final static String driver = "com.mysql.jdbc.Driver";
	
	public Database( String URL, String port, String db, String user, String password ) throws Exception {
		SetURL(URL);
		SetPort(port);
		SetDatabase(db);
		SetUser(user);
		SetPassword(password);
		Class.forName(driver);
		con = DriverManager.getConnection(GetURL() + ":" + GetPort() + "/" + GetDatabase(),
				GetUser(), GetPassword());
		st = con.createStatement();
	}
	
	public ResultSet Query(String Query) throws SQLException {
		if( st != null ) {
			try {
				st.executeQuery(Query);
			} catch (SQLException e) {
				SQLException e2 = new SQLException(e.getMessage() + "\n\tOrignal Query: " + Query);
				e2.setStackTrace(e.getStackTrace());
				throw e2;
			}
		}
		return null;
	}
	/*
	 * 		Mutators
	 */
	void SetDatabase(String db) {
		this.database=db;
	}
	void SetURL( String URL ) {
		this.url = URL;
	}
	void SetPort( String port ) {
		this.port = port;
	}
	void SetUser( String user ) {
		this.user = user;
	}
	void SetPassword( String password ) {
		this.password = password;
	}
	
	/* 
	 *		Retrievers 
	 */
	String GetDatabase() {
		return this.database;
	}
	String GetURL() {
		return this.url;
	}
	String GetPort() {
		return this.port;
	}
	String GetUser() {
		return this.user;
	}
	String GetPassword() {
		return this.password;
	}
	
	
}
